package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.CompanydeptPageDto;
import com.wizz.trade.information.entity.Companydept;
import com.wizz.trade.information.mapper.CompanydeptMapper;
import com.wizz.trade.information.service.CompanydeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 公司部门表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class CompanydeptServiceImpl extends ServiceImpl<CompanydeptMapper, Companydept> implements CompanydeptService {

    @Resource
    private CompanydeptMapper companydeptMapper;

    @Override
    public void addCompanydept(Companydept companydept) {
        companydeptMapper.insert(companydept);
    }

    @Override
    public void updateCompanydept(Companydept companydept) {
        companydeptMapper.updateById(companydept);
    }

    @Override
    public void deleteCompanydept(Integer id) {
        companydeptMapper.deleteById(id);
    }

    @Override
    public PageVo<Companydept> getPage(CompanydeptPageDto companydeptPageDto) {
        LambdaQueryWrapper<Companydept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(companydeptPageDto.getName()),Companydept::getName, companydeptPageDto.getName());
        queryWrapper.eq(!Objects.isNull(companydeptPageDto.getCompany()),Companydept::getCompany, companydeptPageDto.getCompany());
        IPage<Companydept> page = companydeptMapper.selectPage(PageUtil.initPage(companydeptPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Companydept> getAll() {
        return companydeptMapper.selectList(null);
    }

    @Override
    public List<Map<Integer, String>> getDeptNames(Integer companyId) {
        return companydeptMapper.getDeptNames(companyId);
    }

    @Override
    public List<Map<Integer, String>> getOurDeptOptions(Integer companyId) {
        return companydeptMapper.getOurDeptOptions(companyId);
    }

    @Override
    public List<Map<Integer, String>> getCompanyDeptOptions(Integer companyId) {
        return companydeptMapper.getCompanyDeptOptions(companyId);
    }


}
